home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / tttool30.arc / MISC.TTT < prev    next >
Text File  |  1986-09-28  |  6KB  |  204 lines

  1. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2. {                                                                           }
  3. {           T E C H N O J O C K S     T U R B O    T O O L K I T            }
  4. {                                                                           }
  5. {                      Module   :   Misc.TTT                                }
  6. {                                                                           }
  7. {                      Version  :   3.0 , October 1, 1986                   }
  8. {                                                                           }
  9. {                      Purpose  :   Miscellaneous Utilities.                }
  10. {                                                                           }
  11. {                 Requirements  :   Decl.TTT                                }
  12. {                                                                           }
  13. {  Proc   Beep;                                                             }
  14. {         Printscreen;                                                      }
  15. {         Wait_for_Keypress(var Character:char);                            }
  16. {         FlushKeyBuffer;                                                   }
  17. {         Replicate(N:byte;character:char);                                 }
  18. {                                                                           }
  19. {  Func   Int_to_str(Number:integer):string20;                              }
  20. {         Str_to_Int(Str:string80):integer;                                 }
  21. {         Real_to_str(Number:real;Decimals:byte):string20;                  }
  22. {         Printer_Ready:boolean;                                            }
  23. {         Time:string20;                                                    }
  24. {         Date:string30;                                                    }
  25. {         MemAvail_in_Bytes:real;                                           }
  26. {                                                                           }
  27. {                                                Bob Ainsbury               }
  28. {                                                Technojock                 }
  29. {                                                Houston                    }
  30. {                                                (713) 293-2760             }
  31. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  32.  
  33. function time: string20;
  34. var
  35.   recpack:          regpack;             {assign record}
  36.   ah,al,ch,cl,dh:   byte;
  37.   hour,min,sec:     string[2];
  38.   sec_int,
  39.   min_int,
  40.   hour_int,code:    integer;
  41. begin
  42.   ah := $2c;                             {initialize correct registers}
  43.   with recpack do
  44.   begin
  45.     ax := ah shl 8 + al;
  46.   end;
  47.   intr($21,recpack);                     {call interrupt}
  48.   with recpack do
  49.   begin
  50.     str(cx shr 8,hour);                  {convert to string}
  51.     str(cx mod 256,min);                       { " }
  52.     str(dx shr 8,sec);                         { " }
  53.   end;
  54.   val(hour,hour_int,code);
  55.   val(sec,sec_int,code);
  56.   val(min,min_int,code);
  57.   if sec_int<10 then            {pad a leading zero if sec is < 10 }
  58.    begin
  59.      str(sec_int,sec);
  60.      sec := '0'+sec;
  61.    end;
  62.   if min_int<10 then            {pad a leading zero if min is < 10 }
  63.    begin
  64.      str(min_int,min);
  65.      min := '0'+min;
  66.    end;
  67.   if hour_int>12 then           { assign an a.m. or p.m. string }
  68.    begin
  69.     str(hour_int-12,hour);
  70.     IF length(hour) = 1 then Hour := ' '+hour;
  71.     time := hour+':'+min+':'+sec+' p.m.'
  72.    end
  73.    else
  74.     time := hour+':'+min+':'+sec+' a.m.';
  75.   if hour_int=12 then
  76.    time := hour+':'+min+':'+sec+' p.m.';
  77. end;
  78.  
  79. function Date: String30;
  80. type
  81.   WeekDays = array[0..6]  of string[9];
  82.   Months   = array[1..12] of string[9];
  83. const
  84.     DayNames   : WeekDays  = ('Sunday','Monday','Tuesday','Wednesday',
  85.                               'Thursday','Friday','Saturday');
  86.     MonthNames : Months    = ('January','February','March','April','May',
  87.                               'June','July','August','September',
  88.                               'October','November','December');
  89. var
  90.  Year,
  91.  Month,
  92.  Day,
  93.  DayOfWeek : integer;
  94.  YearStr   : string4;
  95.  DayStr    : string2;
  96.  Recpac : regpack;
  97. begin
  98.  with Recpac do
  99.  begin
  100.   Ax := $2A00;
  101.   Intr($21,Recpac);
  102.   DayOfWeek := Lo(Ax);
  103.   Year      := Cx;
  104.   Month     := Hi(Dx);
  105.   Day       := Lo(Dx);
  106.  end;
  107.  Str(Year:4,YearStr);
  108.  Str(Day,DayStr);
  109.  Date := DayNames[DayOfWeek] + ' ' + MonthNames[Month] +
  110.                  ' ' + DayStr + ', ' + YearStr;
  111. end;
  112.  
  113.  
  114. Procedure PrintScreen;
  115. var Regpack : array[1..10] of integer;
  116. begin
  117. intr($05,regpack);
  118. end;
  119.  
  120. procedure Beep;
  121. begin
  122. sound(800);Delay(250);Nosound;
  123. end;
  124.  
  125. procedure Wait_for_keypress(var Character:char);
  126. begin
  127.  Funckey := false;
  128.  read(kbd,Character);
  129.  if (Character = #27) and keypressed then
  130.  begin
  131.   read(kbd,Character);
  132.   Funckey := true;
  133.  end;
  134. end;
  135.  
  136. Function Int_to_Str(Number:Integer):string20;
  137. var Temp : string20;
  138. begin
  139.  Str(Number,temp);
  140.  Int_to_Str := temp;
  141. end;
  142.  
  143. function Real_to_str(Number:real;Decimals:byte):string20;
  144. var Temp : string20;
  145. begin
  146. Str(Number:20:Decimals,Temp);
  147. repeat
  148. If copy(Temp,1,1) = ' ' then delete(Temp,1,1);
  149. until copy(temp,1,1) <> ' ';
  150. Real_to_Str := Temp;
  151. end;
  152.  
  153. Function  Str_to_Int(Str:string80):integer;
  154. var temp,code : integer;
  155. begin
  156. val(Str,temp,code);
  157. if code = 0 then Str_to_Int := temp
  158. else
  159. Str_to_Int := 0;
  160. end;
  161.  
  162. function printer_ready :boolean;
  163. var ah : byte;
  164. begin
  165. ah := 2;
  166. with recpack do
  167.    begin
  168.    ax := ah shl 8;
  169.    dx := 0
  170.    end;
  171. intr($17,recpack);
  172. ah := recpack.ax div 256 ;
  173. if ah = 144 then
  174.    printer_ready := true
  175. else
  176.    printer_ready := false;
  177. end;
  178.  
  179. Procedure FlushKeyBuffer;
  180. begin
  181. with recpack do
  182. begin
  183.  Ax := ($0c shl 8) or 6;
  184.  Dx := $00ff;
  185. end;
  186. Intr($21,recpack);
  187. end;
  188.  
  189. Function MemAvail_in_Bytes:real;
  190. var  Memleft : real;
  191. begin
  192. Memleft := Memavail;
  193. If Memleft < 0 then Memleft := Memleft + 65536.;
  194. MemAvail_in_bytes := Memleft*16;    {16 bytes in a paragraph}
  195. end;   {proc MemAvail_in_Bytes}
  196.  
  197. Function Replicate(N : byte; Character:char):string80;
  198. var tempstr : string80;
  199. begin
  200. If not (N in [1..80]) then N := 1;
  201. fillchar(tempstr,N+1,Character);
  202. Tempstr[0] := chr(N);
  203. Replicate := Tempstr;
  204. end;